<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      outline-style: none;
      border:none;
    }
    div{
      width: 100px;
      height: 100px;
      border: 1px solid #ccc;
      margin: 40px auto;
    }
    input:nth-child(1){
      width: 60px;
      height: 100px;
      float: left;
      box-sizing: border-box;
      text-align: center;
    }
    input[type='button']{
      border: 1px solid #aaa;
      width: 40px;
      height: 50px;
      float: left;
    }
  </style>
</head>
<body>
  <div>
    <input type="text" value="0">
    <input type="button" value="+">
    <input type="button" value="-">
  </div>
  <script>
    var content = document.querySelector('input[type="text"]');
    var add_btn = document.querySelector('input:nth-child(2)');
    var sub_btn = document.querySelector('input:nth-child(3)');
    var num = 0
    add_btn.onclick = function(){
      if(!isNaN(content.value) && content.value >= 0 ){
        num = Number(content.value) + 1;
        content.value = num;
      }else{
        alert('您输入有误 请重新输入');
        content.value = 0;
      }
    }
    sub_btn.onclick = function(){
      if(!isNaN(content.value) && content.value > 0){
        num = Number(content.value)-1;
        content.value = num;
      }else{
        alert('输入不正确')
        content.value = 0;
      }
     
    }
    
  </script>
</body>
</html>